﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Globalization;

using CE.Configuration;
using CE.Global;
using CE.User;

public partial class cmi_cmi_main : MyLanguageBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Master.Page.Title = Resources.Title.CompulsuryInsurance;

        LiteralControl newln = new LiteralControl(Environment.NewLine);
        HtmlMeta language = new HtmlMeta();
        language.Name = "language";
        language.Content = Resources.Title.PageLanguage;

        HtmlMeta keywords = new HtmlMeta();
        keywords.Name = "keywords";
        keywords.Content = Resources.Title.CMIKeyword;
        HtmlMeta description = new HtmlMeta();
        description.Name = "description";
        description.Content = Resources.Title.CMIDescription;

        Page.Header.Controls.AddAt(10, new LiteralControl(Environment.NewLine));
        Page.Header.Controls.AddAt(11, language);
        Page.Header.Controls.AddAt(12, new LiteralControl(Environment.NewLine));
        Page.Header.Controls.AddAt(13, keywords);
        Page.Header.Controls.AddAt(14, new LiteralControl(Environment.NewLine));
        Page.Header.Controls.AddAt(15, description);

        if (!IsPostBack)
        {
            //Session["CMITYPE"] = null;
            Session["CMICARTYPE"] = null;
            Session["CMIPROVIDER"] = null;
            Session["CMITITLE"] = null;
            Session["CMICTPL"] = null;
            Session["CMICTPLDISC"] = null;
            Session["CMITOTAL"] = null;
            Session["CMIINSURER"] = null;
        }
    }

    protected void ctvInsurer_ServerValidate(object source, ServerValidateEventArgs args)
    {
        args.IsValid = rdlInsurer1.Checked || rdlInsurer2.Checked;
    }

    protected void btnNext_Click(object sender, EventArgs e)
    {
        ChangeValidationEffectServerSide("carprofile");
        Page.Validate("carprofile");
        if (Page.IsValid)
        {
            //Session["CMITYPE"] = "2";
            Session["CMICARTYPE"] = rdlVehicleType.SelectedValue;
            Session["CMITITLE"] = rdlVehicleType.SelectedItem.Text + ": " + (rdlInsurer1.Checked == true ? rdlInsurer1.Text : rdlInsurer2.Text);
            //Session["CMIPROVIDER"] 
            if (rdlInsurer1.Checked)
            {
                Session["CMIPROVIDER"] = "11";
            }
            else if (rdlInsurer2.Checked)
            {
                Session["CMIPROVIDER"] = "45";
            }
            Session["CMICTPL"] = hidSumCTPL.Value;
            Session["CMICTPLDISC"] = hidSumDiscount.Value;
            Session["CMITOTAL"] = hidTotal.Value;
            Session["CMIINSURER"] = (rdlInsurer1.Checked == true ? "11" : "45");
            string _redirectUrl = "";
            _redirectUrl = CE.Global.General.GetUrl("~/cmi/cmi-detail.aspx", Page); //~/car-insurance/proposalforms/
            Response.Redirect(_redirectUrl);
        }
    }

    private void ChangeValidationEffectServerSide(string strValidationGroup)
    {
        if (rfvVehicleType.Enabled && rfvVehicleType.ValidationGroup == strValidationGroup)
        {
            rfvVehicleType.Validate();
            if (rfvVehicleType.IsValid == false)
            {
                rdlVehicleType.ControlStyle.CssClass = "validationError";
            }
            else
            {
                rdlVehicleType.ControlStyle.CssClass = "";
            }
        }
        else
        {
            rdlVehicleType.ControlStyle.CssClass = "";
        }

    }
}
